<template>
<onekit-page>
<onekit-view onekit-class="container">
	<div is="onekit-template-head" :DATA="`${JSON.stringify({title:'订阅消息'})}`"></div>
	<onekit-view onekit-class="page-body">
		<onekit-view onekit-class="page-section">
			<template>
				<onekit-text onekit-class="page-body-text">点击提交，调用示例订阅消息</onekit-text>
				<onekit-button onekit-class="page-body-button" type="primary" @Tap="requestSubscribeMessage">提交</onekit-button>
			</template>
		</onekit-view>
	</onekit-view>
	<div is="onekit-template-foot"></div>
</onekit-view>
</onekit-page></template>
<script>
/* eslint-disable */
import Vue from 'vue';
import onekit_template_0 from '../../../common/head.head.vue';Vue.component('onekit-template-head',onekit_template_0);
import onekit_template_1 from '../../../common/foot.foot.vue';Vue.component('onekit-template-foot',onekit_template_1);
const ONEKIT_JSON= {
  "usingComponents": {
    
  }
};
const ONEKIT_SJS = {
};
import wx from '../../../../weixin2vue/wx.js';
import Macro from '../../../../weixin2vue/Macro.js';
const {getApp,getCurrentPages} = Macro;
import Page from '../../../../weixin2vue/OnekitPage.js';
import Component from '../../../../weixin2vue/OnekitComponent.js';
export default Page(ONEKIT_JSON,[],ONEKIT_SJS,{
    "data":{
},
    "requestSubscribeMessage"(){
      const self = this;
      wx.requestSubscribeMessage({
        "tmplIds":[
          'y1bXHAg_oDuvrQ3pHgcODcMPl-2hZHenWugsqdB2CXY'
        ],
        "success"(res){
          console.log(res);
          if(res.errMsg == 'requestSubscribeMessage:ok')
          {
            self.subscribeMessageSend();
          };
        },
        "complete"(res){
          console.log(res);
        }
});
    },
    "subscribeMessageSend"(){
      wx.cloud.callFunction({
        "name":'openapi',
        "data":{
            "action":'sendSubscribeMessage'
},
        "success":(res)=>{
          console.warn('[云函数] [openapi] templateMessage.send 调用成功：',res);
          wx.showModal({
              "title":'订阅成功',
              "content":'请返回微信主界面查看',
              "showCancel":false
});
        },
        "fail":(err)=>{
          wx.showToast({
              "icon":'none',
              "title":'调用失败'
});
          console.error('[云函数] [openapi] templateMessage.send 调用失败：',err);
        }
});
    },
    "onLoad"(options){
    },
    "onReady"(){
    },
    "onShow"(){
    },
    "onHide"(){
    },
    "onUnload"(){
    },
    "onPullDownRefresh"(){
    },
    "onReachBottom"(){
    },
    "onShareAppMessage"(){
      return {
        "title":'订阅消息',
        "path":'packageAPI/pages/subscribe-message/subscribe-message'
};
    }
});

</script>
<style 
 lang="css">
.page-section {
  margin-top: 100px ;
  display: flex ;
  flex-direction: column ;
  align-items: center ;
  justify-content: center ;
  width: 100% ;
  padding: 0 25px ;
  box-sizing: border-box ;
}
.page-body-title {
  font-size: 30px ;
  line-height: 100px ;
}
.page-body-text {
  color: var(--weui-FG-1) ;
  font-size: 14px ;
  line-height: 20px ;
  margin: 0 0 50px 0 ;
  text-align: center ;
}
.page-body-button {
  width: 100% ;
}
</style>